package com.medical_system.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.medical_system.dao.KsDao;
import com.medical_system.entity.KeShi;
import com.medical_system.util.JDBCUtil;


public class KsDaoImpl implements KsDao{
	JDBCUtil util = JDBCUtil.getInit();

	@Override
	public KeShi queryByID(int id) {
		ResultSet rs = util.query("SELECT * from ks where ks_id=?", id);
		try {
			if (rs.next()) {
				KeShi k=new KeShi();
				k.setKsid(rs.getInt("ks_id"));
				k.setKsname(rs.getString("ks_name"));
				return k;
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			util.closeAll();
		}

		return null;

	}

	@Override
	public KeShi queryByName(String name) {
		ResultSet rs = util.query("SELECT * from ks where ks_name=?", name);
		try {
			if (rs.next()) {
				KeShi k=new KeShi();
				k.setKsid(rs.getInt("ks_id"));
				k.setKsname(rs.getString("ks_name"));
				return k;
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			util.closeAll();
		}

		return null;

	}
	@Override
	public List<KeShi> queryAll() {
		ResultSet rs = util.query("select * from ks");
		List<KeShi> list=new ArrayList<KeShi>();
		try {
			while(rs.next()) {
				KeShi k=new KeShi();
				k.setKsid(rs.getInt("ks_id"));
				k.setKsname(rs.getString("ks_name"));
				list.add(k);
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			util.closeAll();
		}
		return list;
		
	}

}
